package biz

import (
	"context"

	"github.com/go-kratos/kratos/v2/log"
)

type News struct {
	Id         int    `json:"id"`
	Title      string `json:"title"`
	Content    string `json:"content"`
	CreateTime string `json:"create_time"`
}

type NewsRepo interface {
	CreateNews(ctx context.Context, new *News) (error, int)
	GetNews(ctx context.Context, newsId int) (error, *News)
	GetListNews(ctx context.Context, page, pageSize int) (error, []*News)
}

type NewsUsecase struct {
	repo NewsRepo
	log  *log.Helper
}

func NewNewsUsecase(repo NewsRepo, logger log.Logger) *NewsUsecase {
	return &NewsUsecase{repo: repo, log: log.NewHelper(logger)}
}

func (uc *NewsUsecase) Create(ctx context.Context, n *News) (err error, id int) {
	return uc.repo.CreateNews(ctx, n)
}

func (uc *NewsUsecase) Get(ctx context.Context, newsId int) (err error, new *News) {
	return uc.repo.GetNews(ctx, newsId)
}

func (uc *NewsUsecase) GetList(ctx context.Context, page, pageSize int) (err error, newList []*News) {
	return uc.repo.GetListNews(ctx, page, pageSize)
}
